//==============================================================================
//
//               Copyright (C) 2002  Dick van Oudheusden
//  
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public
// License as published by the Free Software Foundation; either
// version 2 of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// General Public License for more details.
//
// You should have received a copy of the GNU General Public
// License along with this program; if not, write to the Free
// Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
//
//==============================================================================
// 
//  $Date: 2003-10-31 08:12:33 $ $Revision: 1.1 $
//
//==============================================================================

#include <stdlib.h>

#include "ofc/config.h"

#include "ofc/DArray.h"

#include "DInc.h"
#include "DTest.h"

//-Collections-----------------------------------------------------------------

void DArray_test()
{
  DArray *array1 = [[DArray alloc] init];
  DArray *array2 = [DArray alloc];
  DInc   *test;
  int     i;
   
  STARTTEST();

  [array2 init :10];

  TEST([array1 isValid :0]);

  TEST([array2 isValid :0]);
  TEST([array2 isValid :9]);
  TEST(![array2 isValid :10]);

  TEST([array2 length] == 10);

  for (i = 0; i < [array2 length]; i++)
  {
    [array2 set :i :[DInc new]];
  }

  TEST([[array2 length :20] length] == 20);
  
  test = [array2 get :4];

  TEST([test number] == 5);

  TEST(![array2 has :[DInc new]]);
  TEST( [array2 has :test]);

  [array2 set :11 :test];

  TEST([array2 count :test] == 2);

  TEST([array2 index  :test] == 4);
  TEST([array2 rindex :test] == 11);
  
  [array2 set :11 :nil];

  TEST([array2 count :test] == 1);

  [array2 free];
  [array1 free];

  STOPTEST();
}

